using System;
using System.Collections;
using System.DirectoryServices;

namespace BEGDC.CC.Entity
{
	#region APComment

	/// <summary>
	/// APComment object for NHibernate mapped table 'APComments'.
	/// </summary>
	[Serializable]
	public class APComment : System.IComparable
		{
		#region Member Variables
		
		protected int _id;
		protected int _aPNo;
		protected Nullables.NullableDateTime _date;
		protected string _events;
		protected string _answeredBy;
		protected string _including;
		protected string _attachmentList;
		protected ActionPoint _actionPoint;
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public APComment() { }

		public APComment( int aPNo, Nullables.NullableDateTime date, string events, string answeredBy, string including, string attachmentList, ActionPoint actionPoint )
		{
			this._aPNo = aPNo;
			this._date = date;
			this._events = events;
			this._answeredBy = answeredBy;
			this._including = including;
			this._attachmentList = attachmentList;
			this._actionPoint = actionPoint;
		}

		#endregion

		#region Public Properties

		public int Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public int APNo
		{
			get { return _aPNo; }
			set { _aPNo = value; }
		}

		public Nullables.NullableDateTime Date
		{
			get { return _date; }
			set { _date = value; }
		}

		public string Events
		{
			get { return _events; }
			set
			{
				if ( value != null && value.Length > 2000)
					throw new ArgumentOutOfRangeException("Invalid value for Events", value, value.ToString());
				_events = value;
			}
		}

		public string AnsweredBy
		{
			get { return _answeredBy; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for AnsweredBy", value, value.ToString());
				_answeredBy = value;
			}
		}

		public string Including
		{
			get { return _including; }
			set
			{
				if ( value != null && value.Length > 250)
					throw new ArgumentOutOfRangeException("Invalid value for Including", value, value.ToString());
				_including = value;
			}
		}

		public string AttachmentList
		{
			get { return _attachmentList; }
			set
			{
				if ( value != null && value.Length > 250)
					throw new ArgumentOutOfRangeException("Invalid value for AttachmentList", value, value.ToString());
				_attachmentList = value;
			}
		}

		public ActionPoint ActionPoint
		{
			get { return _actionPoint; }
			set { _actionPoint = value; }
		}

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public int CompareTo(object obj)
        {
			if (!(obj is APComment))
				throw new InvalidCastException("This object is not of type APComment");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((APComment)obj).Id);
					break;
				case "APNo":
					relativeValue = this.APNo.CompareTo(((APComment)obj).APNo);
					break;
				case "Date":
						relativeValue = ( this.Date != null ) ? this.Date.CompareTo(((APComment)obj).Date) : -1;
					break;
				case "Events":
						relativeValue = ( this.Events != null ) ? this.Events.CompareTo(((APComment)obj).Events) : -1;
					break;
				case "AnsweredBy":
						relativeValue = ( this.AnsweredBy != null ) ? this.AnsweredBy.CompareTo(((APComment)obj).AnsweredBy) : -1;
					break;
				case "Including":
						relativeValue = ( this.Including != null ) ? this.Including.CompareTo(((APComment)obj).Including) : -1;
					break;
				case "AttachmentList":
						relativeValue = ( this.AttachmentList != null ) ? this.AttachmentList.CompareTo(((APComment)obj).AttachmentList) : -1;
					break;
                default:
                    goto case "Id";
			}
            if (APComment.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
